<template>
    <div class="on-sale-good-car">
        <div class="search-content">
            <el-input class="search-content-input" v-model="searchContent.store_id" placeholder="请输入店铺ID"></el-input>
            <el-input class="search-content-input" v-model="searchContent.store_name" placeholder="请输入经销商名称"></el-input>
            <el-input class="search-content-input" v-model="searchContent.store_owner" placeholder="请输入公司名称"></el-input>
			<el-input class="search-content-input" v-model="searchContent.member_name" placeholder="请输入账号名称"></el-input>
			<el-input class="search-content-input" v-model="searchContent.out_request_no" placeholder="请输入业务申请编号"></el-input>
            <el-input class="search-content-input" v-model="searchContent.applyment_id" placeholder="请输入微信支付申请编号"></el-input>
            <el-input class="search-content-input" v-model="searchContent.sub_mchid" placeholder="请输入电商平台二级商业号"></el-input>
			<el-select v-model="searchContent.wechat_applyment_state" placeholder="微信申请状态">
                <el-option
                    v-for="item in jituanList"
                    :label="item.label"
                    :key="item.value"
                    :value="item.value">
                </el-option>
            </el-select>
            <el-select v-model="searchContent.ali_applyment_state" placeholder="支付宝 申请状态">
                <el-option
                    v-for="item in alijituanList"
                    :label="item.label"
                    :key="item.value"
                    :value="item.value">
                </el-option>
            </el-select>
            <el-select 
                v-model="searchContent.depart_id" 
                placeholder="请选择集团">
                <el-option
                    v-for="item in groupList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
            </el-select>        
            <el-button type="primary" @click="search">搜索</el-button>
            <el-button type="primary" @click="resetSearchData">重置</el-button>
            <el-button type="primary" @click="update">微信更新</el-button>
            <el-button type="primary" @click="updateAli">支付宝更新</el-button>
        </div>        
        <div class="search-list">
            <el-table :data="memberList" border :height="oHeight">
                <el-table-column align="center" type="selection" width="55">
                </el-table-column>
                <el-table-column
                    align="center"
                    prop="store_id"
                    label="ID"
                    min-width="100"
                ></el-table-column>
                <el-table-column
                    align="center"
                    prop="store_name"
                    label="经销商名称"
                    min-width="120"
                ></el-table-column>
                <el-table-column
                    align="center"
                    prop="store_owner"
                    label="公司名称"
                    min-width="120"
                ></el-table-column>
                <el-table-column
                    align="center"
                    prop="member_name"
                    label="账号名称"
                    min-width="120"
                ></el-table-column>
                <el-table-column
                    align="center"
                    prop="wechat_sub_mchid"
                    label="微信支付电商平台二级商户号"
                    min-width="120"
                ></el-table-column> 
                <el-table-column
                    align="center"
                    prop="wechat_applyment_state_desc"
                    label="微信支付申请状态"
                    min-width="120"
                ></el-table-column> 
                <el-table-column
                    align="center"
                    prop="ali_sub_mchid"
                    label="支付宝电商平台二级商户号"
                    min-width="120"
                ></el-table-column> 
                <el-table-column
                    align="center"
                    prop="ali_applyment_state_desc"
                    label="支付宝申请状态"
                    min-width="120"
                ></el-table-column>                                 
                <el-table-column
                    align="center"
                    label="操作"
                    min-width="190">
                        <template slot-scope="scope">
                            <el-button v-if="scope.row.wechat_detail_button == 0" @click="memberAdd(scope.row.store_id,scope.row.out_request_no,0)" type="primary" size="mini">微信添加</el-button>
                            <el-button v-if="scope.row.wechat_detail_button == 1" @click="storeDetail(scope.row.store_id)" type="primary" size="mini">微信查看</el-button>
                            <el-button v-if="scope.row.wechat_applyment_state == 'REJECTED' || scope.row.wechat_applyment_state == 'CANCELED'"  @click="memberAdd(scope.row.store_id,scope.row.out_request_no,1)" type="primary" size="mini">微信编辑</el-button>
                            <el-button v-if="scope.row.ali_detail_button == 0" @click="memberAddAli(scope.row.store_id,1)" type="primary" size="mini">支付宝添加</el-button>
                            <el-button v-if="scope.row.ali_detail_button == 1"  @click="memberAddAli(scope.row.store_id,2)" type="primary" size="mini">支付宝查看</el-button>
                            <el-button v-if="scope.row.ali_applyment_state == '-1'" @click="memberAddAli(scope.row.store_id,3)" type="primary" size="mini">支付宝编辑</el-button>
                        </template>                    
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group">
                    <!-- <el-button
                        size="mini"
                        type="primary"
                        class="btn-bottom"
                        @click="expertData"
                        >导出</el-button
                    > -->
                    <!-- <button type="button" class="btn-bottom" @click="showDeleteDialog">删除</button> -->
                </div>
                <!--分页部分-->
                <div class="paginationOne">
                    <el-button
                        size="mini"
                        type="primary"
                        class="btn-bottom"
                        @click="expertData"
                        >导出</el-button
                    >                 
                    <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="searchContent.page"
                        :page-sizes="[10, 20, 50, 100]"
                        :page-size="searchContent.pageSize"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total"
                    >
                    </el-pagination>
                </div>
            </div>
        </div>
		<add-store ref="add" v-on:getList="getList"></add-store>
		<add-store-ali ref="addAli"></add-store-ali>
        <store-edit ref='edit'></store-edit>
    </div>
</template>
<script>
import { resize } from "@/common/js/height.js";
import storeEdit from './store-edit';
import addStore from './add-store';
import addStoreAli from './add-store-alipay.vue';

export default {
    components: {addStore,storeEdit,addStoreAli},
    data() {
        return {
            memberList: [],
            oHeight: 800,
            searchContent: {
                pageSize:localStorage.getItem('pageSize') * 1 || 10,//
                page:1,
                store_name:'',
                store_owner:'',
                member_name:'',
                out_request_no:'',
                applyment_id:'',
                sub_mchid:'',
                wechat_applyment_state:'',
                ali_applyment_state:"",
                store_id:'',
                depart_id:'',
            },          
            searchObj:{},
            jituanList:[],
            alijituanList:[],
            total: 0,
            needUnshelveGoods: null,
            dialogVisible: false,
            dialogMsg: '',
            groupList: [],
        };
	},
	created(){
        this.getList();
        this.getState();
	},
    methods: {
        // 新增店铺开户编辑
		memberAdd(data1,data2,state){
            this.$refs.add.show_dialog_fn(data1,data2,state);
        },
        memberAddAli(id,key){
            this.$refs.addAli.show_dialog_fn(id,key);
        },
        // 详情
        storeDetail(id){
            var that = this;
            that.$refs.edit.show_dialog_fn1(id);
        },  
        expertData() {
            /* var host = location.host.replace('admin', api);
            var url = location.protocol + "//" + host + '/admin/appointment/index.php?act=appoint&op=appointList&is_export=1';
            var searchData = this.searchObj;
            for (var key in searchData) {
                if (!(searchData[key] === null || searchData[key] === '' || searchData[key] === undefined || key === 'page' || key === 'pageSize' || key === 'currentPage')) {
                    url += '&' + key + '=' + searchData[key]
                }
            }
            console.log(url);
            window.location.href = url; */
        },
        handleSizeChange(pageSize) {
            localStorage.setItem('pageSize', pageSize);
            this.searchContent.pageSize = pageSize;
            this.searchContent.page = 1;
            this.getList();
        },
        handleCurrentChange(page) {
            this.searchContent.page = page;
            this.getList();
        },
        // 重置
        resetSearchData() {
            this.searchObj = {};
            this.searchContent={
                page:1,
                pageSize:localStorage.getItem('pageSize')*1||10,
            }
            this.getList();            
        },
        // 搜索
        search() {
            this.searchContent.page = 1;
            this.searchObj = {
                store_name: this.searchContent.store_name,
                store_owner:this.searchContent.store_owner,
                member_name:this.searchContent.member_name,
                out_request_no: this.searchContent.out_request_no,
                applyment_id: this.searchContent.applyment_id,
                sub_mchid: this.searchContent.sub_mchid,
                wechat_applyment_state: this.searchContent.wechat_applyment_state, 
                ali_applyment_state: this.searchContent.ali_applyment_state, 
                store_id:this.searchContent.store_id,        
                depart_id:this.searchContent.depart_id                     
            }
            this.getList();
        },    
        //更新状态
        update(){
            this.$http.post('/admin/bill/index.php?act=storeSubCall&op=merchantAudit').then((res)=>{
                if(res.code==1){
                    this.$message({
                    showClose: true,
                    message: '更新状态成功',
                    type: 'success'
                    });
                }else{
                    this.$message({
                    showClose: true,
                    message: res.msg,
                    type: 'error'
                    });                    
                }
            })
        },
        updateAli(){
            this.$http.post("/admin/bill/index.php?act=storeMchAli&op=checkProcess").then(res=>{
                console.log(res,'rrreeesss');
            })
        },
        //下拉状态list
        getState(){
            this.$http.post('/admin/bill/index.php?act=storeMchSetting&op=getApplymentStates').then((res)=>{
                if(res.data){
                    this.jituanList = res.data;
                }else{
                    this.jituanList = [];
                }
            })
            this.$http.post('/admin/bill/index.php?act=storeMchSetting&op=getApplymentStates&type=2').then((res)=>{
                if(res.data){
                    this.alijituanList = res.data;
                }else{
                    this.alijituanList = [];
                }
            })
            this.$http.post('/crm/coupons/index.php?act=statistics&op=getCouponDepart')
            .then(res => {
                if (res.data) {
                    this.groupList = [
                        { label: '全部', value: 0 },
                        ...res.data.map(item => ({ 
                            label: item.depart_name, 
                            value: parseInt(item.depart_id) 
                        }))
                    ]
                }
            }).catch(error => {
                error && this.$message.error(`${error}`)
            })            
        },  
        //列表  
		getList(){
            var data = this.searchObj;
            data.page = this.searchContent.page;
            data.pageSize = this.searchContent.pageSize;
            this.$http.post('/admin/bill/index.php?act=storeMch&op=storeMchList',data).then((res)=> {
                if (res.code == 1) {
                    if (res.data && res.data.list.length) {
                        // this.memberList = res.data.list;
                        this.total = parseInt(res.data.totalCount);
                        this.memberList = res.data.list.map(function(item) {
                            return {
                                store_id: item.store_id,
                                store_name: item.store_name,
                                store_owner: item.store_owner,
                                member_name: item.member_name,
                                out_request_no: item.out_request_no,
                                applyment_id: item.applyment_id,
                                sub_mchid: item.sub_mchid,
                                applyment_state_desc: item.applyment_state_desc,
                                wechat_detail_button:item.wechat_detail_button,
                                wechat_applyment_state: item.wechat_applyment_state,
                                ali_detail_button:item.ali_detail_button,
                                ali_applyment_state: item.ali_applyment_state,
                                wechat_sub_mchid: item.wechat_sub_mchid,
                                wechat_applyment_state_desc: item.wechat_applyment_state_desc,
                                ali_sub_mchid: item.ali_sub_mchid,
                                ali_applyment_state_desc: item.ali_applyment_state_desc,
                            }
                        });                        
                    } else {
                        this.memberList = [];
                        this.total = 0;
                    }

                }
                else if (res.code == 2001) {
                    this.memberList = [];
                    this.total = 0;
                }
                else {
                    alert(res.msg);
                }
            })			
        },
        //导出
        expertData(){
            var data = this.searchObj;
            data.is_export = "1";   
            let domain = document.domain;
            var url = location.protocol + '//' + domain.replace('admin', 'api') + '/admin/bill/index.php?act=storeMch&op=storeMchList';               
            for (var key in data) {
                    if (
                    !(
                        data[key] === null ||
                        data[key] === "" ||
                        data[key] === undefined
                    )
                    ) {
                    url += "&" + key + "=" + data[key];
                    }
                }    
            window.location.href = url;              
        }
        
    },
    mounted() {
        resize(this)
    },
};
</script>
<style lang="scss" scoped>
    .on-sale-good-car {
        .search-content {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            &-input {
                width: 200px;
            }
            .putaway-time-wrapper {
                .putaway-time-label {
                    font-size: 14px;
                }
                display: flex;
                align-items: center;
                /deep/.el-range-separator {
                    box-sizing: content-box;
                }
            }
        }
    }
    .paginationOne{
        width: 100%;
        display: flex;
        justify-content: space-between;
    }
	.bottom{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>